package hot;

public class erbaisi {
//    https://leetcode.cn/problems/search-a-2d-matrix-ii/?envType=study-plan-v2&envId=top-100-liked

        static int m;
        static int n;
        static int i=0;
        public static boolean searchMatrix(int[][] matrix, int target) {
            m=matrix.length;
            n=matrix[0].length;
            while(i<m){
                if(n==0){
                    return false;
                }
                if(target>matrix[i][n-1]){
                    i++;
                }else if(target<matrix[i][n-1]){
                    n=n-1;
                }else{
                    return true;
                }
            }
            return false;
        }

    public static void main(String[] args) {
//        int[][] num={{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
        int[][] num={{-5}};
        boolean b = searchMatrix(num, -10);
        System.out.println(b);
    }

}
